<?php
/**
 * Created by PhpStorm.
 * User: beijingwhg
 * Date: 2017/5/11
 * Time: 下午2:50
 */

namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\Auth\Factory as Auth;

class HomeAuth
{
    protected $auth;

    public function __construct(Auth $auth)
    {
        $this->auth = $auth;
    }

    public function handle($request, Closure $next)
    {
        if ($this->auth->guard('user')->check()) {
            return $next($request);
        }

        if ($this->auth->guard('admin')->check()) {
            $request->session()->put('isAdmin', 1);

            return $next($request);
        }

        $request->session()->put('intend',$request->getRequestUri());

        return redirect('/login');
    }
}